<?php 

$expires = 60*5*1*1;
header("Pragma: public");
header("Cache-Control: maxage=".$expires);
header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expires) . ' GMT');


$listlink	= listLinkCategory();
SaveSitemap($listlink);
//print_r($listlink);
exit;

function listLinkCategory($idParent=0,$urlParent='')
{
global $dbsql;
	
	$sql_select="select iId,cUrlString,iParentId from tblcategory where iParentId=$idParent
				 and cType!='home' and iStatus=1 order by iOrder";
	$rs=$dbsql->query($sql_select);
	$listlink=array();
	while ($result=$dbsql->fetch_array($rs)) {
		$listlink[]=$urlParent.$result['cUrlString'];
		
		$linkchilds=listLinkCategory($result['iId'],$urlParent.$result['cUrlString'].'/');	
		$listlink=array_merge($listlink,$linkchilds);
		
	}
	return $listlink;
}
	

function SaveSitemap($links)
{
	global $root_domain,$folder_path_root;
	
	$filename='../sitemap.xml';
	
	$dom = new DOMDocument();
	$dom->formatOutput = true;
	$xml_string="<?xml version=\"1.0\" encoding=\"UTF-8\"?><urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 		http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\"><url><loc>".$root_domain."</loc></url></urlset>";
	$dom->loadXML($xml_string);
	$root=$dom->documentElement;	
	$listlink	= array();
	
	foreach($links as $i => $link)
	{
		$cLink=$root_domain.$folder_path_root.$link;
		if(in_array($cLink,$listlink))
		{
			continue;
		}
		$listlink[]=$cLink;
		$cLink=str_replace("–","-",$cLink);
		$url_E = $dom->createElement('url');			
		$loc_E = $dom->createElement('loc',$cLink);
		$url_E->appendChild($loc_E);
		$root->appendChild($url_E);		
	}			
	$dom->save($filename);	
}
	
	
	
?>
